import React, { useEffect ,useState} from 'react'
import { getNewsAPI } from '../../apis/home'
import { List,Image } from 'antd-mobile'
import { baseURL } from '../../utils/request'

export default function News() {
    const [newsLists, setNewsLists] = useState([])
    async function getNews() {
        const res = await getNewsAPI()
        // console.log(res.body)
        setNewsLists(res.body)
    }
    useEffect(()=> {
        getNews()
    },[])
    return (
        <div>
            {/* 咨询 */}
            <List header='最新资讯' className='home__news'>
                {newsLists.map(item => (
                    <List.Item
                        key={item.id}
                        prefix={
                            <Image
                                src={baseURL + item.imgSrc}
                                fit='cover'
                            />
                        }
                    >
                        <div>
                            <p>{item.title}</p>
                            <span className='from'>{item.from}</span>
                            <span className='date'>{item.date}</span>
                        </div>
                    </List.Item>
                ))}
            </List>
        </div>
    )
}
